package Year22_Month05.day30;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Employee2 {
    public static List<Employee> filterEmployee(List<Employee> list,MyPredict<Employee> predict){
        List<Employee> emps =  new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Employee emp = list.get(i);
            if(predict.test(emp)){
                emps.add(emp);
            }
        }
        return emps;
    }

    public static void main(String[] args) {
        List<Employee> emps = Arrays.asList(
                new Employee("张三","男", 20, 5000),
                new Employee("李四","男", 36, 7000),
                new Employee("王五","男", 16, 3000),
                new Employee("赵六","女", 23, 6000),
                new Employee("田七","男", 43, 8000)
        );
        //匿名内部类
        List<Employee> list5 = filterEmployee(emps, new MyPredict<Employee>() {
            @Override
            public boolean test(Employee employee) {
                return  employee.getAge() > 35;
            }
        });
        List<Employee> list6 = filterEmployee(emps, new MyPredict<Employee>() {
            @Override
            public boolean test(Employee employee) {
                return  employee.getSalary() >= 5000;
            }
        });

    }
}
